'use strict'

module.exports = appInfo => {
  const config = exports = {}

  config.keys = `${appInfo.name}_1525862516758_9048`

  // 中间件
  config.middleware = [ 'handleError', 'loader', 'search', 'pagination' ]

  // 注意跨域问题
  config.search = {
    enable: true,
    match: ctx => ctx.method === 'GET' || ctx.method === 'OPTIONS',
  }

  // 安全配置
  config.security = {
    csrf: {
      enable: false,
    },
  }
  // MongoDB 数据库
  config.mongoose = {
    url: 'mongodb://127.0.0.1/wivwiv-egg',
    options: {
      useNewUrlParser: true,
      useCreateIndex: true,
    },
  }

  config.redis = {
    client: {
      port: 6379,
      host: '127.0.0.1',
      password: '',
      db: 0,
    },
  }
  // 微信小程序支付 https://www.npmjs.com/package/weixinpay
  config.weixinpay = {
    // pfx: fs.readFileSync('xxx/xxx/apiclient_cert.p12'),可选，退款需要
    appid: '',
    openid: '',
    mch_id: '',
    partner_key: '',
  }

  config.bodyParser = {
    jsonLimit: '2mb',
    formLimit: '2mb',
  }

  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  }

  return config
}
